package com.woniuxy.service;

import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author: 马宇航
 * @Description: ai的工具调用的，生成正常的消息，但是需要它们变成死信
 * @DateTime: 25/10/28/星期二 11:10
 * @Component: 成都蜗牛学苑
 **/
@Service //@Component,@Repository,@Controller 是一样的，但是和@Configuration
public class DeadMessageServiceTools {
    @Autowired
    RabbitTemplate rabbitTemplate;
    @Tool(description = "把消息发送到队列中")
    public void sendMessage(String msg){
        rabbitTemplate.convertAndSend("ttl.exchange","ttl.routing.key",msg);
    }
    @Tool(description = "把消息发送到最大长度队列中")
    public void sendMaxMessage(String msg){
        rabbitTemplate.convertAndSend("maxLengthExchange","maxLength",msg);
    }
    @Tool(description = "把消息发送到延迟队列中")
    public void sendDelayMessage(String msg){
        rabbitTemplate.convertAndSend("delayExchange","delay",msg,
                (Message message)->{
            //方法1
//            message.getMessageProperties().setHeader("x-delay",10000);
            //方法2:底层有断言校验入参，避免负数，和超级大的值
            message.getMessageProperties().setDelayLong(10000l);
            message.getMessageProperties().setUserId("guest");
            return message;
        });
    }
}
